package controller
{
	import display.DisplayPlayer;
	import display.DisplayScrollPane;
	import events.PresetEvent;
	
	import events.DisplayEvent;
	
	import flash.display.Stage;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	public class Controller extends EventDispatcher
	{
		private var shell:Shell;
		private var data:Array;
		
		private var scrollPane:DisplayScrollPane;
		private var player:DisplayPlayer;
		
		private var presetControl:PresetControl;
		
		public function Controller(sh:Shell)
		{
			shell = sh;
		}
		
		public function start(scroll:DisplayScrollPane,play:DisplayPlayer,presetctr:PresetControl):void
		{
			scrollPane = scroll;
			player = play;
			
			//settings controller
			presetControl = presetctr;
			presetControl.addEventListener(DisplayEvent.ON_PRESET_CHANGED, onPresetChanged);
			
			player.addEventListener(DisplayEvent.VISIBILITY_CHANGED, onVisibilityChanged);
			
			scrollPane.addEventListener(DisplayEvent.COLOR_CHANGED, onColorChanged);
			scrollPane.addEventListener(DisplayEvent.ALPHA_CHANGED, onAlphaChanged);
			scrollPane.addEventListener(DisplayEvent.FONT_CHANGED, onFontChanged);
			scrollPane.addEventListener(DisplayEvent.ON_HIGHLIGHT, onHighLight);
		}
		
		private function onHighLight(e:DisplayEvent):void
		{
			dispatchEvent(new DisplayEvent(DisplayEvent.ON_HIGHLIGHT, { state:e.data.state, item:e.data.item } ));
		}
		
		private function onVisibilityChanged(e:DisplayEvent):void
		{
			dispatchEvent(new DisplayEvent(DisplayEvent.VISIBILITY_CHANGED, { item:e.data.item ,selected:e.data.selected} ));
		}
		
		private function onPresetChanged(e:DisplayEvent):void
		{
			dispatchEvent(new DisplayEvent(DisplayEvent.ON_PRESET_CHANGED, {presetData:e.data.presetItem} ));
		}
		
		private function onFontChanged(e:DisplayEvent):void
		{
			dispatchEvent(new DisplayEvent(DisplayEvent.FONT_CHANGED, { font:e.data.font } ));
		}
		
		private function onAlphaChanged(e:DisplayEvent):void
		{
			dispatchEvent(new DisplayEvent(DisplayEvent.ALPHA_CHANGED, { alpha:e.data.alpha,category:e.data.category,itemCategory:e.data.itemCategory } ));
		}
		
		private function onColorChanged(e:DisplayEvent):void
		{
			dispatchEvent(new DisplayEvent(DisplayEvent.COLOR_CHANGED,{colorOne:e.data.colorOne,colorTwo:e.data.colorTwo,category:e.data.category,itemCategory:e.data.itemCategory}));
		}
	}
}